package com.bst.bsj.portal.util;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * 方便 对xml 进行序列化 类XmlUtil.java的实现描述：TODO 类实现描述
 * 
 * @author cyf 2015年1月5日 上午10:24:25
 */
public class XmlUtil {

    private static XStream xstream;

    private static XmlUtil xmlUtil;

    private XmlUtil(){

    }

    public static XmlUtil newInstance() {

        if (null == xstream) {
            xstream = new XStream(new DomDriver());
        }
        if (null == xmlUtil) {
            xmlUtil = new XmlUtil();
        }
        return xmlUtil;

    }

    @SuppressWarnings("unchecked")
    public <T> T deserializer(String xml, String name, Class<T> clazz) {
        xstream.alias(name, clazz);
        T t = (T) xstream.fromXML(xml);
        return t;
    }
}
